const App = {
    data() {
        return {
            form: {
                Agricultural_Machinery_Name:'',
                Province_Number:'',
                Ctiy_Number:'',
                County_Number:'',
                Town_Number:'',
                Village_Number:'',
                Contact_Phone:'',
                User_Name:'',
                Agricultural_Machinery_Ownership:'230106200105091715',
                Open_ID: 'oxS4B7tyTRYszs_PFjslwTGAV6yE',
                Row_Status:'2'
            },
            nodeKey: '',
            cityValue: ["230000", "232700", "232723"],
            cityValue1: [],
            city: [],
            city1: [],
        }
    },
    beforeCreate() {
        function setRem() {
            const designWidth = 750; // 设计稿宽度（rpx）
            const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
            const screenWidth = Math.min(window.innerWidth, maxWidth);
            const scale = screenWidth / designWidth;
            document.documentElement.style.fontSize = scale + 'px';
        }
        setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
        window.addEventListener('resize', setRem);
    },
    mounted() {
        let ls_URL = window.location.href;
        this.nodeKey = getQueryObject(ls_URL, "nodeKey");// 获取 nodeKey 参数
        this.getCity();
        this.changeCity(this.cityValue);
    },
    methods: {
        changeCity(val) {
            if (val.length > 0) {
                this.form.Province_Number = val[0];
                this.form.Ctiy_Number = val[1];
                this.form.County_Number = val[2];
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/clientOperation/getDistrictTree`,
                    type: "GET",
                    data: {
                        DistrictCode: val[2],
                    },
                    success: (data) => {
                        this.city1 = data[0].children;
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }
        },
        getCity() {
            $.ajax({
                url: `${absolutepath()}api/Districtjl.json`,
                method: "get",
                success: (data) => {
                    data.forEach((item) => {
                        item.children.forEach((ite) => {
                            ite.children.forEach((it) => {
                                it.children = undefined;
                            });
                        });
                    });
                    this.city = data;
                },
            });
        },
        handle() {
            let lJSONObject_DataSet = {
                Add: {
                    agricultural_machinery: [this.form],
                }
            }
            $.ajax({
                headers: requestHeaders("JSON"),
                url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                method: "post",
                data: JSON.stringify({
                    Data: lJSONObject_DataSet,
                }),
                success: (res) => {
                    if (res.Status == 'success') {
                        this.$message({
                            message: '成功',
                            type: 'success'
                        });
                    }
                },
                complete: (XMLHttpRequest) => {
                    this.loading = false;
                    requestPretreatment(XMLHttpRequest)
                }
            });
        },
        changeCity1(val) {
            console.log(val);
            if (val.length > 0) {
                this.form.Town_Number = val[0];
                this.form.Village_Number = val[val.length - 1];
            } else {
                this.form.Village_Number = "";
            }
        },
        handle1() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/queryMultiTableByCondition`,
                type: "POST",
                data: {
                    Data: JSON.stringify([{
                        tableName: 'room_type_check_ins',
                        Condition: window.btoa(unescape(encodeURIComponent("Room_Type_Bookings_SerialNumber='" + this.nodeKey + "'"))),
                    }, {
                        tableName: 'room_type_bookings',
                        Condition: window.btoa(unescape(encodeURIComponent("Room_Type_Bookings_SerialNumber='" + this.nodeKey + "'"))),
                    }]),
                },
                success: ({ room_type_check_ins, room_type_bookings }) => {
                    room_type_check_ins[0].Row_Status = '0';
                    room_type_bookings[0].Row_Status = '5';
                    console.log(room_type_bookings, room_type_check_ins);
                    let lJSONObject_DataSet = {
                        Modify: {
                            room_type_check_ins,
                            room_type_bookings
                        }
                    }
                    $.ajax({
                        headers: requestHeaders("JSON"),
                        url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                        method: "post",
                        data: JSON.stringify({
                            Data: lJSONObject_DataSet,
                        }),
                        success: (res) => {
                            if (res.Status == 'success') {
                                this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                            }
                        },
                        complete: (XMLHttpRequest) => {
                            this.loading = false;
                            requestPretreatment(XMLHttpRequest)
                        }
                    });
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            })

        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
